import React, { useContext } from 'react'
import { Table, Button } from 'antd'
import IconSvg from '@/components/IconSvg'
import { hospitalAdminUserContext } from '../../../context'
import { findNamesByIds } from '@/utils'

export default () => {
  const { cityTopConfig, topConfigData, tableConfig, inpatientWardBottomConfig } = useContext(hospitalAdminUserContext)

  const columns: any = [
    // { width: 40 },
    {
      title: '医院编码',
      dataIndex: 'hospitalCode',
      key: 'hospitalCode',
      width: 100,
      align: 'center',
    },
    {
      title: '医院名称',
      dataIndex: 'unitName',
      key: 'unitName',
      width: 180,
      align: 'center',
    },
    {
      title: '所属地区',
      dataIndex: 'regions',
      width: 240,
      align: 'center',
      render: (value: any) => <span>{findNamesByIds(topConfigData.topRegionSelectData, value).join('/')}</span>,
    },
    {
      title: '病区一级分类',
      dataIndex: 'oneLevelWardName',
      key: 'oneLevelWardName',
      width: 120,
      align: 'center',
    },
    {
      title: '病区二级分类',
      dataIndex: 'twoLevelWardName',
      key: 'twoLevelWardName',
      width: 120,
      align: 'center',
    },
    {
      title: '负责人姓名',
      dataIndex: 'username',
      key: 'username',
      width: 120,
      align: 'center',
    },
    {
      title: '联系电话',
      dataIndex: 'phone',
      key: 'phone',
      width: 120,
      align: 'center',
    },
    {
      title: '登录次数',
      dataIndex: 'loginCount',
      key: 'loginCount',
      width: 108,
      align: 'center',
      sorter: (a: any, b: any) => a.loginCount - b.loginCount,
      //   sortOrder: 'descend',
    },
    {
      title: '上次登录时间',
      dataIndex: 'lastLoginDate',
      width: 240,
      align: 'center',
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: 80,
      fixed: 'right',
      align: 'center',
      render: (_: any, record: any) => (
        <div style={{ display: 'flex', justifyContent: 'space-around', alignItems: 'center' }}>
          <Button
            type='link'
            // loading={detailUpdateLoading.includes(record.id)}
            onClick={() => inpatientWardBottomConfig.inpatientWardExamine(record)}
          >
            <IconSvg name='cityExamine' style={{ marginRight: 5 }} />
            查看
          </Button>
        </div>
      ),
    },
  ]
  return (
    <div>
      <div>
        <Table
          rowKey='id'
          dataSource={tableConfig.tableData}
          columns={columns}
          rowSelection={topConfigData.rowSelection}
          pagination={{
            position: ['bottomRight'],
            total: cityTopConfig.paging.totalCount,
            onChange: (page: any, pageSize: any) => {
              cityTopConfig.changePagingUploadTable(page, pageSize)
            },
            showTotal: (total: number) =>
              `共 ${total} 条记录  第 ${cityTopConfig.paging.pageIndex} / ${Math.ceil(
                total / cityTopConfig.paging.pageSize,
              )}页`,
            current: cityTopConfig.paging.pageIndex,
            pageSize: cityTopConfig.paging.pageSize,
            showSizeChanger: true,
          }}
          scroll={{ x: 'max-content', y: 'calc(100vh - 360px)' }}
        />
      </div>
    </div>
  )
}
